package com.myspring.resttest;

import java.util.ArrayList;
import java.util.List;

import javax.validation.Valid;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.myspring.resttest.model.SpringHibernateUser;
import com.myspring.resttest.model.Student;
import com.myspring.resttest.model.StudentList;
import com.myspring.resttest.service.SpringHibernateUserManager;

@RestController
public class DataController {
	@Autowired
	SpringHibernateUserManager userManager;
	Logger logger = Logger.getLogger(DataController.class);

	@RequestMapping(value = "studentdead", method = RequestMethod.GET)
	public Student getStudent(
			@RequestParam(value = "username", defaultValue="kasachde") String uname) {
		SpringHibernateUser user = new SpringHibernateUser();
		user = userManager.getUser("kasachde");
		logger.info("User has full name as " + user.getName());
		logger.error("Username provided is "+uname);
		logger.info("Inside the right controller with json handler triggered\n");
		return new Student(23, "Meghnaa", "Naidu", "meghna@gmail.com",
				"8978767878");
	}

	@RequestMapping("studentlist")
	public StudentList getStudentList() {
		List<Student> studentList = new ArrayList<Student>();
		studentList.add(new Student(3, "Robert", "Parera", "robert@gmail.com",
				"8978767878"));
		studentList.add(new Student(93, "Andrew", "Strauss",
				"andrew@gmail.com", "8978767878"));
		studentList.add(new Student(239, "Eddy", "Knight", "knight@gmail.com",
				"7978767878"));

		return new StudentList(studentList);
	}

}